package com.aix.demo.api.os;

import java.io.File;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.TextView;

import com.aix.demo.R;

public class EnvironmentActivity extends Activity {
	
	private TextView mTextView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_environment);

		mTextView = (TextView) findViewById(R.id.textview1);
		
		StringBuilder builder = new StringBuilder();
		
		File dataDirectory = Environment.getDataDirectory();
		buildFileStats(builder, "Environment.getDataDirectory():", dataDirectory);
		
		File downloadCacheDir = Environment.getDownloadCacheDirectory();
		buildFileStats(builder, "Environment.getDownloadCacheDirectory():", downloadCacheDir);
		
		String state = Environment.getExternalStorageState();
		builder.append("\nExternalStorageState : " + state);
		
		File externalStorageDir = Environment.getExternalStorageDirectory();
		buildFileStats(builder, "Environment.getExternalStorageDirectory():", externalStorageDir);
		
		mTextView.setText(builder.toString());
	}
	
	private void buildFileStats(StringBuilder builder, String description, File file) {
		String absolutePath = file.getAbsolutePath();
		String filename = file.getName();
		String path = file.getPath();
		
		builder.append("\n" + description);
		builder.append("\nabsolute path : " + absolutePath);
		builder.append("\nfile name : " + filename);
		builder.append("\npath : " + path);
	}
}
